package tr3dtris.game.models;

/**
 * Class used to model a single cell of a grid. A cell could by empty or full.
 * A full cell is filled by a <Block>. Cells are used to build <CellArray>s.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class Cell implements Cloneable
{

    /**
     * Reference for the block contained into the <Cell>
     */
    protected Block block;

    /**
     * Blank constructor. Creates a <Cell> with no <Block> inside.
     */
    public Cell()
    {
        this.block = null;
    }

    /**
     * Constructor. Creates a cell with a given <Block> instance.
     * @param block
     */
    public Cell(Block block)
    {
        this.block = block;
    }

    /**
     * @return the block
     */
    public Block getBlock()
    {
        return block;
    }

    /**
     * @param block the block to set
     */
    public void setBlock(Block block)
    {
        this.block = block;
    }

    /**
     * Check if the cell is empty
     * @return true if the cell is empty, false otherwise
     */
    public boolean isEmpty()
    {
        return (this.block == null);
    }

    /**
     * Deletes the block inside the cell
     */
    public void free()
    {
        this.block = null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object clone()
    {
        if(this.isEmpty())
            return new Cell();

        return new Cell((Block)this.getBlock().clone());
    }

}
